import request, { type ListQuery, type ListResponse } from "@/utils/request";
import { type RegionalAgentItemType } from "../user/regionalAgent";
import { type UserProfileType } from "../user/profile";

const SUPPLIER_APPLY_BASE_URL = "/api";

export const SupplierApplyApi = {
  getSupplierApplyList: (params: ListQuery) => {
    return request.get<any, ListResponse<SupplierApplyItemType>>(
      `${SUPPLIER_APPLY_BASE_URL}/internal/SupplierApply/`,
      { params }
    );
  },
  getSupplierApplyDetail: (id: number) => {
    return request.get<any, SupplierApplyItemType>(
      `${SUPPLIER_APPLY_BASE_URL}/internal/SupplierApply/${id}/`
    );
  },
  addSupplierApply: (data: Partial<SupplierApplyForm>) => {
    return request.post(`${SUPPLIER_APPLY_BASE_URL}/internal/SupplierApply/`, data, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },
  updateSupplierApply: (data: Partial<SupplierApplyForm>) => {
    return request.put(`${SUPPLIER_APPLY_BASE_URL}/internal/SupplierApply/${data.id}/`, data, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },
  deleteSupplierApply: (id: number | string) => {
    return request.delete(`${SUPPLIER_APPLY_BASE_URL}/internal/SupplierApply/${id}/`);
  },
};

export type SupplierApplyListQuery = {} & ListQuery;

export type SupplierApplyStatus = "approve" | "reject";

export type SupplierApplyItemType = {
  id: number | string;
  agent: RegionalAgentItemType;
  user: UserProfileType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  name: string;
  contact_name: string;
  contact_phone: string;
  contact_email: string;
  status: SupplierApplyStatus;
  business_license_url: string;
  id_card_1: string;
  id_card_2: string;
  reason: string;
};

export type SupplierApplyForm = {
  id?: string | number;
  is_active: boolean;
  name: string;
  contact_name: string;
  contact_phone: string;
  contact_email: string;
  status: SupplierApplyStatus;
  business_license_url: string | File;
  id_card_1: string | File;
  id_card_2: string | File;
  reason: string;
  agent?: number | string;
  user: number | string;
};

export default SupplierApplyApi;
